﻿using AutoMapper;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SystemCenterSoa.ApiProject.Controllers;
using SystemCenterSoa.DtoModel.Common;
using SystemCenterSoa.DtoModel.SystemManager;
using SystemCenterSoa.PoModel.SystemManager;
using SystemCenterSoa.Service.SystemManager;

namespace SystemCenterSoa.ApiProject.Area.SystemManager
{
    public class WebSystemMenuManagerController : MyBaseController
    {
        private WebSystemMenuService _webSystemMenuBll;
        public WebSystemMenuManagerController(WebSystemMenuService webSystemMenuBll)
        {
            _webSystemMenuBll = webSystemMenuBll;
        }

        [HttpGet]
        public ResultModel<WebSystemMenuViewDto> GetWebSystemMenuViewByCode(string code)
        {
            try
            {
                var data = _webSystemMenuBll.GetWebSystemMenuViewByCode(code);
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<WebSystemMenuViewDto>(ex);
            }
        }

        [HttpPost]
        public ResultModel<bool> WSMUpdate(WebSystemMenuPo wsm)
        {
            try
            {
                var data = _webSystemMenuBll.MenuUpdate(wsm);
                return MyOk<bool>(data);
            }
            catch (Exception ex)
            {

                return MyError<bool>(ex);
            }
        }

        [HttpGet]
        public ResultModel<List<WebSystemMenuPo>> GetModuleDbsAll()
        {
            try
            {
                var data = _webSystemMenuBll.GetWebSystemMenuAll();
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<List<WebSystemMenuPo>>(ex);
            }
        }
        [HttpGet]
        public ResultModel<List<WebSystemMenuViewDto>> GetWebSystemMenuViewsAll()
        {
            try
            {
                var data = _webSystemMenuBll.GetWebSystemMenuViewsAll();
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<List<WebSystemMenuViewDto>>(ex);
            }
        }

     

        [HttpGet]
        public ResultModel<bool> VMenuCode(string wmc)
        {
            try
            {
                var data = _webSystemMenuBll.VMenuCode(wmc);

                return MyOk<bool>(data);
            }
            catch (Exception ex)
            {
                return MyError<bool>(ex);
            }
        }

        [HttpPost]
        public ResultModel<bool> WSMAdd(WebSystemMenuPo wsm)
        {
            if (string.IsNullOrWhiteSpace(wsm.wm_code))
            {
                return MyFail<bool>("请输入菜单code");
            }
            if (!_webSystemMenuBll.VMenuCode(wsm.wm_code))
            {
                return MyFail<bool>("菜单code已经被使用,请重新输入其他菜单Code");
            }


            wsm.creator_date = DateTime.Now;
            wsm.creator_name = LoginUser.user_name;
            try
            {
                var data = _webSystemMenuBll.MenuAdd(wsm);
                return MyOk<bool>(data);
            }
            catch (Exception ex)
            {
                return MyError<bool>(ex);
            }
        }


        [HttpGet]
        public ResultModel<List<WebSystemMenuViewDto>> GetUserWebSystemMenu()
        {
            try
            {
                var data = _webSystemMenuBll.GetUserWebSystemMenus();
                return MyOk(data);
            }
            catch (Exception ex)
            {
                return MyError<List<WebSystemMenuViewDto>>(ex);
            }
        }
    }
}
